home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / datamgr / faddindx.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-10-23  |  7.6 KB  |  264 lines

  1. VERSION 2.00
  2. Begin Form fAddIndex 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Add Index"
  6.    ClientHeight    =   3930
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1485
  9.    ClientWidth     =   7350
  10.    Height          =   4335
  11.    Left            =   1035
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   3930
  16.    ScaleWidth      =   7350
  17.    Top             =   1140
  18.    Visible         =   0   'False
  19.    Width           =   7470
  20.    Begin CommandButton cCancel 
  21.       Cancel          =   -1  'True
  22.       Caption         =   "Cancel"
  23.       Height          =   375
  24.       Left            =   6000
  25.       TabIndex        =   10
  26.       Top             =   720
  27.       Width           =   1095
  28.    End
  29.    Begin CommandButton cDone 
  30.       Caption         =   "&Done"
  31.       Height          =   375
  32.       Left            =   6000
  33.       TabIndex        =   9
  34.       Top             =   240
  35.       Width           =   1095
  36.    End
  37.    Begin CommandButton cRemove 
  38.       Caption         =   "&Remove"
  39.       Enabled         =   0   'False
  40.       Height          =   375
  41.       Left            =   2520
  42.       TabIndex        =   4
  43.       Top             =   2400
  44.       Width           =   1095
  45.    End
  46.    Begin CommandButton cAdd 
  47.       Caption         =   "Add (D&ec)"
  48.       Enabled         =   0   'False
  49.       Height          =   375
  50.       Index           =   1
  51.       Left            =   2520
  52.       TabIndex        =   3
  53.       Top             =   1920
  54.       Width           =   1095
  55.    End
  56.    Begin CommandButton cAdd 
  57.       Caption         =   "&Add (Asc)"
  58.       Enabled         =   0   'False
  59.       Height          =   375
  60.       Index           =   0
  61.       Left            =   2520
  62.       TabIndex        =   2
  63.       Top             =   1440
  64.       Width           =   1095
  65.    End
  66.    Begin TextBox cIndexName 
  67.       Height          =   285
  68.       Left            =   360
  69.       TabIndex        =   0
  70.       Top             =   360
  71.       Width           =   2055
  72.    End
  73.    Begin CheckBox cPrimary 
  74.       BackColor       =   &H00C0C0C0&
  75.       Caption         =   "&Primary Index"
  76.       Height          =   255
  77.       Left            =   3840
  78.       TabIndex        =   8
  79.       Top             =   3600
  80.       Width           =   1695
  81.    End
  82.    Begin CheckBox cUnique 
  83.       BackColor       =   &H00C0C0C0&
  84.       Caption         =   "Require &Unique Index Values"
  85.       Height          =   255
  86.       Left            =   480
  87.       TabIndex        =   7
  88.       Top             =   3600
  89.       Width           =   2895
  90.    End
  91.    Begin ListBox cFields 
  92.       Height          =   2370
  93.       Left            =   3720
  94.       TabIndex        =   6
  95.       Top             =   960
  96.       Width           =   2040
  97.    End
  98.    Begin ListBox cFieldList 
  99.       Height          =   2370
  100.       Left            =   360
  101.       Sorted          =   -1  'True
  102.       TabIndex        =   1
  103.       Top             =   975
  104.       Width           =   2040
  105.    End
  106.    Begin Label cTableName 
  107.       Caption         =   "cTableName"
  108.       Height          =   255
  109.       Left            =   4320
  110.       TabIndex        =   5
  111.       Top             =   3960
  112.       Visible         =   0   'False
  113.       Width           =   2535
  114.    End
  115.    Begin Label Label3 
  116.       BackColor       =   &H00C0C0C0&
  117.       Caption         =   "&Index Name:"
  118.       Height          =   255
  119.       Left            =   360
  120.       TabIndex        =   13
  121.       Top             =   120
  122.       Width           =   2055
  123.    End
  124.    Begin Label Label2 
  125.       BackColor       =   &H00C0C0C0&
  126.       Caption         =   "Field&s in Index"
  127.       Height          =   255
  128.       Left            =   3720
  129.       TabIndex        =   12
  130.       Top             =   720
  131.       Width           =   1815
  132.    End
  133.    Begin Label Label1 
  134.       BackColor       =   &H00C0C0C0&
  135.       Caption         =   "&Fields in Table"
  136.       Height          =   255
  137.       Left            =   360
  138.       TabIndex        =   11
  139.       Top             =   720
  140.       Width           =   1935
  141.    End
  142. Sub cAdd_Click (Index As Integer)
  143.     Dim PlMn As String
  144.     PlMn = "+"
  145.     If Index = 1 Then PlMn = "-"
  146.     cFields.AddItem PlMn & cFieldList.List(cFieldList.ListIndex)
  147.     cFieldList.RemoveItem cFieldList.ListIndex
  148.     cFieldList.ListIndex = -1
  149.     For I = 0 To 1
  150.         cAdd(I).Enabled = False
  151.     Next I
  152.     If cFields.ListCount > 0 And cIndexName <> "" Then
  153.         cDone.Enabled = True
  154.         cDone.Default = True
  155.     End If
  156.     cFieldList.SetFocus
  157. End Sub
  158. Sub cCancel_Click ()
  159. 'Close Dialog
  160. Unload fAddIndex
  161. End Sub
  162. Sub cDone_Click ()
  163.     Dim idx As New Index
  164.     Dim tempFields As String
  165.     Dim temp As String
  166.     Dim I As Integer
  167.     Dim AddErr As Integer
  168.     On Error Resume Next
  169.     'Set up index properties
  170.     idx.Name = cIndexName
  171.     idx.Primary = -cPrimary
  172.     idx.Unique = -cUnique
  173.     tempFields = ""
  174.     For I = 0 To cFields.ListCount - 1
  175.         temp = cFields.List(I)
  176.         temp = Left$(temp, 1) & "[" & Right$(temp, Len(temp) - 1) & "]"
  177.         tempFields = tempFields + temp + ";"
  178.     Next I
  179.     If Len(tempFields) > 255 Then
  180.         MsgBox "Too many fields in Index.  Remove some and try again.", 64, "Data Manager"
  181.     Else
  182.         'Remove the last semicolon
  183.         idx.Fields = Left$(tempFields, Len(tempFields) - 1)
  184.         
  185.         'Append to the Index Collection
  186.         gDatabase.TableDefs(cTableName).Indexes.Append idx
  187.         AddErr = Err
  188.         If AddErr <> 0 Then
  189.             MsgBox "Error Adding Index: " + Chr$(13) + Error$, 64, "Data Manager"
  190.         End If
  191.         If AddErr = 3283 Then 'Primary Key already exists
  192.             'cPrimary = 0
  193.         ElseIf AddErr = 3277 Then 'Too many fields in list
  194.             cFields.ListIndex = 0
  195.         Else
  196.             'Close Dialog
  197.             Unload fAddIndex
  198.         End If
  199.     End If
  200. End Sub
  201. Sub cFieldList_Click ()
  202.     If cFieldList.ListIndex <> -1 Then
  203.         cAdd(0).Enabled = True
  204.         cAdd(1).Enabled = True
  205.         cRemove.Enabled = False
  206.         cFields.ListIndex = -1
  207.         cAdd(0).Default = True
  208.     End If
  209. End Sub
  210. Sub cFieldList_DblClick ()
  211.     'Add the item
  212.     cAdd_Click (0)
  213. End Sub
  214. Sub cFields_Click ()
  215.     If cFields.ListIndex <> -1 Then
  216.         cFieldList.ListIndex = -1
  217.         cRemove.Enabled = True
  218.         cAdd(0).Enabled = False
  219.         cAdd(1).Enabled = False
  220.     End If
  221. End Sub
  222. Sub cFields_DblClick ()
  223.     'Remove the item
  224.     cRemove_Click
  225. End Sub
  226. Sub cIndexName_Change ()
  227.     If cFields.ListCount > 0 And cIndexName <> "" Then
  228.         cDone.Enabled = True
  229.         cDone.Default = True
  230.     Else
  231.         cDone.Enabled = False
  232.     End If
  233. End Sub
  234. Sub cRemove_Click ()
  235.     Dim temp As String
  236.     temp = cFields.List(cFields.ListIndex)
  237.     cFields.RemoveItem cFields.ListIndex
  238.     cFieldList.AddItem Right$(temp, Len(temp) - 1)
  239.     If cFields.ListCount <= 0 Then
  240.         cDone.Enabled = False
  241.     End If
  242.     cFieldList.ListIndex = 0
  243.     cFieldList.SetFocus
  244. End Sub
  245. Sub Form_Activate ()
  246.     Dim I As Integer
  247.     Dim TD As Tabledef
  248.     Dim FieldCount As Integer
  249.     On Error Resume Next
  250.     Screen.MousePointer = 11
  251.     Set TD = gDatabase.TableDefs(cTableName.Caption)
  252.     FieldCount = TD.Fields.Count
  253.     If FieldCount > 0 Then 'it should be
  254.         For I = 0 To FieldCount - 1
  255.             If TD.Fields(I).Type <= 10 Then  'not ole or memo
  256.                 cFieldList.AddItem TD.Fields(I).Name
  257.             End If
  258.         Next I
  259.     End If
  260.     Screen.MousePointer = 0
  261.     'enable buttons
  262.     cDone.Enabled = False
  263. End Sub
  264.